<template>
  <!-- 首检操作(操作员) -->
  <p-card :bordered="false" :class="'cust-erp-sub-tab'">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <p-form layout="inline" @keyup.enter.native="searchQuery">
        <p-row :gutter="24"></p-row>
      </p-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">

      <p-button v-if="mainId" @click="handleAdd" type="primary" icon="plus">新增</p-button>

      <p-dropdown v-if="selectedRowKeys.length > 0">
        <p-menu slot="overlay">
          <p-menu-item key="1" @click="batchDel">
            <p-icon type="delete" />删除
          </p-menu-item>
        </p-menu>
        <p-button style="margin-left: 8px">
          批量操作
          <p-icon type="down" />
        </p-button>
      </p-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>


      <p-page-header
              style="border: 1px solid rgb(235, 237, 240)"
              title="首检操作"
      >
        <template slot="extra">
          <p-button  @click="saveBtn" type="primary" >保存</p-button>
          <p-popconfirm
                  v-if="inspectResult==1"
                  title="确定要提交吗？"
                  ok-text="确定"
                  cancel-text="取消"
                  @confirm="submitData"
                  @cancel="cancel"
          >
            <p-button type="primary" >提交</p-button>
          </p-popconfirm>

          <p-button @click="backToIndex">取消</p-button>
        </template>
      </p-page-header>

      <h4 class="title">基础信息</h4>


      <p-form :form="form">
        <p-row>
          <p-col :span="8">
            <p-form-item label="送检单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['inspectBillno']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="生产工单" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['productionBillno']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="工序工单" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['processBillno']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="产品编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['mcode']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="产品名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['mname']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="二级工序" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['processTwo']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="线体" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['linename']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="设备编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['device_code']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="检验次数" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['inspectTimes']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <!-- <p-col :span="8">
            <p-form-item label="检验人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['inspect_by']"></p-input>
            </p-form-item>
          </p-col>-->

          <p-col :span="8">
            <p-form-item label="送检时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['sendInspectTime']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="SN" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <!--<p-input v-model="basicSn" placeholder="请扫描或者输入SN" :disabled="basicSnDisabled" @keyup.enter="snEnterOpe"></p-input>-->

              <p-input-search
                      v-model="basicSn" placeholder="请扫描或者输入SN" :disabled="basicSnDisabled"
                      enter-button="确定"
                      @search="snEnterOpe"
              />
            </p-form-item>
          </p-col>

          <!-- <p-col :span="8">
            <p-form-item label="线号/组件编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input
                v-decorator="['palletno']"
                placeholder="请输入线号/组件编号"
              ></p-input>
            </p-form-item>
          </p-col>-->
        </p-row>
      </p-form>

      <h4 class="title">质量判定</h4>

      <p-form-model-item label="检验结果" prop="region" style="display:flex;">
        <p-tag v-if="inspectResult==1" color="green"><p-icon type="check-circle" />合格</p-tag>
        <p-tag v-else-if="inspectResult==2" color="red"><p-icon type="close-circle" />不合格</p-tag>

      </p-form-model-item>

      <h4 class="title">检验项目</h4>
      <!-- 表格 -->
      <p-table
              ref="table"
              size="middle"
              bordered
              rowKey="id"
              :scroll="tableScroll"
              :columns="columns"
              :dataSource="dataSource"
              :loading="loading"
              @change="handleTableChange"
      >
        <!-- 实测值 -->
        <template slot="measuredValue" slot-scope="text,record">
          <p-input
                  v-if="record.valueType==1"
                  v-model="record.measuredValue"
                  type="number"
                  style="width:100px"
                  @change="measuredValueInputChange(record.key)"
          />

          <p-select v-else v-model="record.measuredValue"  style="width: 100px;" @change="measuredValueChange(record.key)">
            <p-select-option value="PASS">PASS</p-select-option>
            <p-select-option value="NG">NG</p-select-option>
          </p-select>
        </template>

        <template slot="remark" slot-scope="text,record">
          <!--<p-input v-model="record.remark" @keyup.enter="detailRemarkEnter(record.key)"/>-->

          <div  v-if="record.remarkNeed">
            <p-input-search
                    v-model="record.remark" placeholder="请扫描或者输入SN"
                    enter-button="确定"
                    @search="detailRemarkEnter(record.key)"
            />
          </div>
          <div v-else>
            {{record.remark}}
          </div>
        </template>

        <div
                slot="filterDropdown"
                slot-scope="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"
                style="padding: 8px"
        >
          <p-input
                  v-ant-ref="c => (searchInput = c)"
                  :placeholder="`请输入 ${column.title}`"
                  :value="selectedKeys[0]"
                  style="width: 188px; margin-bottom: 8px; display: block;"
                  @change="e => setSelectedKeys(e.target.value ? [e.target.value] : [])"
          />
          <p-button
                  type="primary"
                  icon="search"
                  size="small"
                  style="width: 90px; margin-right: 8px"
                  @click="() => handleSearch(selectedKeys, confirm, column.dataIndex)"
          >确认</p-button>
          <p-button size="small" style="width: 90px" @click="() => handleReset(clearFilters)">取消</p-button>
        </div>
        <div
                slot="filterDropdownDate"
                slot-scope="{ selectedKeys, confirm, clearFilters, column }"
                style="padding: 8px"
        >
          <p-form-item :label="` ${column.title}`">
            <j-date
                    :show-time="true"
                    date-format="YYYY-MM-DD HH:mm:ss"
                    placeholder="请选择开始时间"
                    class="query-group-cust"
                    v-model="queryParam[`${column.dataIndex}_begin`]"
            ></j-date>
            <span class="query-group-split-cust"></span>
            <j-date
                    :show-time="true"
                    date-format="YYYY-MM-DD HH:mm:ss"
                    placeholder="请选择结束时间"
                    class="query-group-cust"
                    v-model="queryParam[`${column.dataIndex}_end`]"
            ></j-date>
          </p-form-item>
          <p-button
                  type="primary"
                  icon="search"
                  size="small"
                  style="width: 90px; margin-right: 8px"
                  @click="() => handleSearchDate(selectedKeys, confirm, column.dataIndex)"
          >确认</p-button>
          <p-button
                  size="small"
                  style="width: 90px"
                  @click="() => handleResetDate(clearFilters,`${column.dataIndex}_begin`,`${column.dataIndex}_end`)"
          >取消</p-button>
        </div>
        <p-icon
                slot="filterIcon"
                slot-scope="filtered"
                type="search"
                :style="{ color: filtered ? '#108ee9' : undefined }"
        />

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <img
                  v-else
                  :src="getImgView(text)"
                  height="25px"
                  alt="图片不存在"
                  style="max-width:80px;font-size: 12px;font-style: italic;"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
          <p-button
                  v-else
                  :ghost="true"
                  type="primary"
                  icon="download"
                  size="small"
                  @click="uploadFile(text)"
          >下载</p-button>
        </template>


      </p-table>
    </div>

    <h4 class="title">审批记录</h4>
    <div>
      <p-table
              ref="table"
              size="middle"
              bordered
              rowKey="id"
              :columns="approvalColumns"
              :dataSource="approvalList"
      >

      </p-table>
    </div>


    <mesQcInspectTaskChild-modal
            ref="modalForm"
            :EnhanceJS="EnhanceJS"
            @ok="modalFormOk"
            :mainId="mainId"
            :listaip="this.url.list"
    ></mesQcInspectTaskChild-modal>
  </p-card>
</template>

<script>
  /*导入数字字典*/
  import {
    initDictOptions,
    filterMultiDictText,
  } from "@/components/dict/JDictSelectUtil";
  import { axios } from "@/utils/request";
  import {
    postAction,
    getAction,
    deleteAction,
    httpAction,
    putAction,
    api,
  } from "@/api/manage";
  import { JeecgListMixin } from "@/mixins/JeecgListMixin";
  import MesQcInspectTaskChildModal from "./modules/MesQcInspectTaskChildModal";
  import ButtonExpHandler from "@/components/jeecgbiz/modules/ButtonExpHandler";

  //弹窗复制过来的包
  import { SubmitOnchangMixin } from "@/mixins/SubmitOnchangMixin";
  import pick from "lodash.pick";
  import JDate from "@/components/jeecg/JDate";
  import JSelectUserByDep from "@/components/jeecgbiz/JSelectUserByDep";
  import JDictSelectTag from "@/components/dict/JDictSelectTag";

  export default {
    name: "MesQcInspectTaskChildList",
    mixins: [JeecgListMixin],
    components: { MesQcInspectTaskChildModal },
    props:['mqVisible','mqLoad','mqData'],
    /*watch: {
      mainId: {
        immediate: true,
        handler(val) {
          if (!this.mainId) {
            this.clearList();
          } else {
            this.queryParam["mesInspectTaskId"] = val;
            this.loadData(1);
          }
        },
      },
    },*/
    data() {
      return {
        form: this.$form.createForm(this),
        inspectResult: '', // 质量判定的 检验结果
        dataSource: [], //表格的数据源
        //弹窗复制过来的数据
        title: "操作",
        width: 800,
        visible: false,
        model: { inspectBillno: "1" }, //对表单输入框的数据进行赋值的对象;
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        basicSn:'',
        confirmLoading: false,
        basicSnDisabled:false,
        inspectBillno: "",
        productionBillno: "",
        processBillno: "",
        rules: "",
        mcode: "",
        mname: "",
        operationDt: "",
        confirmTime: "",
        confirmBy: "",
        sn: "",
        palletno: "",

        url: {
          //数据库接口
          add: "/mes-quality/mesQcInspectTask/add",
          edit: "/mes-quality/mesQcInspectTask/edit",

          list: "/mes-quality/mesQcInspectTask/listMesQcInspectTaskChildByMainId",
          delete: "/mes-quality/mesQcInspectTask/deleteMesQcInspectTaskChild", //表格组件获得后台API的数据
          deleteBatch:
                  "/mes-quality/mesQcInspectTask/deleteBatchMesQcInspectTaskChild",
          getColumns: "/mes-quality/online/cgform/api/getColumns/",
          buttonAction: "/mes-quality/online/cgform/api/doButton",
        },
        //end

        description: "首检操作(操作员)页面",
        disableMixinCreated: true,
        EnhanceJS: "",
        cgButtonLinkList: [],
        cgButtonList: [],
        methodList:[],
        methodMap:[],
        standardUnitList:[],
        standardUnitMap:[],

        approvalColumns:[
          {
            title: "序号",
            dataIndex: "",
            key: "rowIndex",
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            },
          },
          {
            title: "时间",
            dataIndex: "createTime",
            customRender: (text) => {

              return this.formatDate(text+'',"YYYY-MM-DD HH:mm:ss");
            },
          },
          {
            title: "操作人员",
            dataIndex: "opeBy",
          },
          {
            title: "操作内容",
            dataIndex: "remark",
          },
          {
            title: "检验不合格工站",
            dataIndex: "inspectFailName",
            customRender: (text) => {
              if(!text){
                return '';
              }
              return text.replaceAll(',','，');
            },
          },
          {
            title: "状态",
            dataIndex: "opeContent",
          },
        ],

        code: "",
        dictOptions: {
          inspectStatus: [],
          inspectResult: [],
          valueType: [],
          individualJudgment: [],
        },
        // 表头
        columns: [
          {
            title: "序号",
            dataIndex: "",
            key: "rowIndex",
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            },
          },
          {
            title: "工站",
            align: "center",
            dataIndex: "workStation",
          },
          {
            title: "检验项目",
            align: "center",
            dataIndex: "inspectProject",
          },
          {
            title: "检验标准",
            align: "center",
            dataIndex: "inspectStandard",
          },
          {
            title: "值类型",
            align: "center",
            dataIndex: "valueType",
            customRender: (text) => {
              if (!text) {
                return "";
              } else {
                return  text==1?'计量型':'计数型';
              }
            },
          },
          {
            title: "检验手段",
            align: "center",
            dataIndex: "inspectMethod",
            customRender:(text)=>{
              if(!text){
                return "";
              }else{
                if(this.methodMap[text]){
                  return this.methodMap[text].title;
                }
                return  "";
              }
            }
          },
          {
            title: "参数",
            align: "center",
            dataIndex: "paramValue",
          },
          {
            title: "单位",
            align: "center",
            dataIndex: "standardUnit",
            customRender: (text) => {
              return this.standardUnitMap[text]?this.standardUnitMap[text].title:'';

            },
          },
          {
            title: "标准值",
            align: "center",
            dataIndex: "standardValue",
          },

          {
            title: "上限值",
            align: "center",
            dataIndex: "upperValue",
          },
          {
            title: "下限值",
            align: "center",
            dataIndex: "downValue",
          },

          {
            title: "实测值",
            align: "center",
            dataIndex: "measuredValue",
            scopedSlots: { customRender: "measuredValue" },
          },
          {
            title: "单项判定",
            align: "center",
            dataIndex: "individualJudgment",
            customRender: (text) => {
              if (!text) {
                return "";
              } else {
                return  text==1?'PASS':'NG';
              }
            },
          },
          {
            title: "检验人",
            align: "center",
            dataIndex: "judge",
          },
          {
            title: "备注",
            align: "center",
            dataIndex: "remark",
            scopedSlots: { customRender: "remark" },
          },

        ],
      };
    },

    computed: {
      /*tableScroll: function () {
        if (this.columns.length > 12) {
          return { x: this.columns.length * 160 + 40 };
        }
      },*/
    },

    created() {
      this.getMethodList();
      this.initStandardUnitList();
      this.mqListener();
      this.setdefColumns();
      this.initButtonList();
    },
    mounted() {


    },

    /* updated() {
       this.initDictConfig();
       this.pan_ding();
     },*/
    methods: {

      mqListener(){
        console.log(this.mqVisible)
        console.log(this.mqLoad)
        console.log(this.mqData)
        this.initData(this.mqData.id);
      },
      backToIndex(){
        let mqData = this.mqData;
        this.$emit('update:mqVisible', 1);
        this.$emit('update:mqLoad', false);
        mqData.id = 0;
        mqData.isPallet = "";
        mqData.inspectStatus = "";
        this.$emit('update:mqData', mqData);
      },



      snEnterOpe(){

        let sn = this.basicSn;
        let id = this.mqData.id;

        let data={
          id:id,
          sn:sn
        }

        postAction('/mes-quality/mesQcInspectTask/checkSn',data).then(res=>{
          if(res.success){
            this.$message.success('操作成功!');
            this.initData(this.mqData.id);
          }else{
            this.$message.warning(res.msg);
          }
        })
      },

      getMethodList(){
        getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'mes_inspect_method'}).then(res=>{
          if(res.success){
            this.methodList = res.data;
            this.methodMap = this.listToMap(this.methodList,'value');
          }
        })
      },

      initStandardUnitList(){
        getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'mes_details_tamplate_unit'}).then(res=>{
          if(res.success){
            this.standardUnitList = res.data;
            this.standardUnitMap = this.listToMap(this.standardUnitList,'value');
          }
        })
      },

      //封装listToMap
      listToMap(list,name){
        let map = {};
        for(let i in list){
          map[list[i][name]] = list[i];
        }
        return map;
      },
      saveBtn(){
        console.log(123)
        let data= this.model;
        data.mesQcInspectTaskChildList = this.dataSource;
        data.inspectResult = this.inspectResult;
        console.log(data)


        putAction('/mes-quality/mesQcInspectTask/save',data).then(res=>{
          if(res.success){
            this.$message.success("保存成功！");
            this.initData(this.mqData.id);
          }else{
            this.$message.warning(res.msg);
          }
        })

      },


      submitData(){
        let flag = true;
        let flag1 = true;

        this.dataSource.forEach(item=>{
          if(!item.measuredValue){
            flag = false;
            flag1 = false;
          }else{
            if(item.measuredValue==''){
              flag = false;
              flag1 = false;
            }
          }
        })

        if(!flag1){
          this.$message.error("请完善每条检验项目的实测值！");
        }

        if(flag){
          let data= this.model;

          data.mesQcInspectTaskChildList = this.dataSource;
          data.inspectResult = this.inspectResult;

          putAction('/mes-quality/mesQcInspectTask/updateMesQcInspectTask',data).then(res=>{
            if(res.success){
              this.$message.success("提交成功！");
              this.backToIndex();
            }else{
              this.$message.warning(res.msg);
            }
          })
        }


      },

      initData(id){
        // 获得表单和表格的数据
        getAction(`/mes-quality/mesQcInspectTask/selectById`, {id:id})
                .then((response) => {
                  if(response.code!=0){
                    this.$message.warning(response.msg)
                  }
                  this.model = response.data;
                  this.basicSn = response.data.sn;
                  if(response.data.sn&&response.data.sn!=''){
                    this.basicSnDisabled = true;
                  }

                  this.inspectResult = response.data.inspectResult;

                  this.edit(this.model); //设置表单的值
                  this.dataSource = response.data.mesQcInspectTaskChildList;
                  this.approvalList = response.data.mesQcApproveRecordList;
                  this.checkDetailDataToBasic();
                  let key = 1;
                  this.dataSource.forEach(item=>{
                    item.key  = key;
                    key = key+1;
                    if(item.remark&&item.remark!=''){
                      item.remarkNeed = false;
                    }else{
                      item.remarkNeed = true;
                    }
                  })
                  console.log("接口返回数据成功", response);
                  console.log(response.data);
                })
                .catch((response) => {
                  console.log("接口无返回数据", response);
                });
      },



      edit(record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.model.inspectBy = this.$store.state.user.name;
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(
                  //设置表单的值
                  pick(
                          this.model,
                          "inspectBillno",
                          "productionBillno",
                          "processBillno",
                          "mcode",
                          "mname",
                          "processTwo",
                          "linename",
                          "deviceCode",
                          "inspectTimes",
                          "inspectBy",
                          "sendInspectTime",
                          "palletno",
                          "sn"
                  )
          );
        });
      },
      //end

      //提交表单的数据
      submit_button() {
        this.model.mesQcInspectTaskChildList = this.dataSource;
        this.model.inspectResult = this.inspectResult;
        console.log("提交表单数据", this.model);
        putAction(`/mes-quality/mesQcInspectTask`, this.model)
                .then((response) => {
                  console.log("提交表单数据成功", response.data);
                  console.log(response.data);
                })
                .catch((response) => {
                  console.log("提交表单数据失败", response);
                });
      },

      /**
       *值类型为计数型 实测值为下拉选项框PASS值为1和NG值为2 值变动触发的提交动作
       */
      measuredValueChange(key) {
        this.dataSource[key-1].judge = this.$store.state.user.name
        this.checkDetailDataToBasic();
      },

      measuredValueInputChange(key){
        this.dataSource[key-1].judge = this.$store.state.user.name
        this.checkDetailDataToBasic();},

      detailRemarkEnter(key){
        let productionBillno  = this.model.productionBillno;
        let cid = this.dataSource[key-1].id;
        let remark = this.dataSource[key-1].remark;

        let data={
          productionBillno:productionBillno,
          inspectProjectId:cid,
          remark:remark
        }

        postAction('/mes-quality/mesQcInspectTask/checkInspectProjectSn',data).then(res=>{
          if(res.success){
            this.$message.success('操作成功！')
            this.initData(this.mqData.id);
          }else{
            this.$message.warning(res.msg)
          }
        })
      },

      //检查细表实测值
      checkDetailDataToBasic(){
        let flag = true;
        this.dataSource.forEach(item=>{
          if(item.measuredValue||item.measuredValue!=""){
            if(item.valueType==2){
              if(item.standardValue==item.measuredValue){
                item.individualJudgment =1
              }else{
                item.individualJudgment =2
                flag = false;
              }
            }else{
              let downValue = 0;
              let upperValue = 0;

              let measuredValue = parseFloat(item.measuredValue);

              if((item.downValue&&item.downValue!='')&&(item.upperValue&&item.upperValue!='')){
                downValue = parseFloat(item.downValue);
                upperValue = parseFloat(item.upperValue);
                if(measuredValue>=downValue&&measuredValue<=upperValue){
                  item.individualJudgment =1
                }else{
                  item.individualJudgment =2
                  flag = false;
                }
              }else if((!item.downValue||item.downValue=='')&&(item.upperValue&&item.upperValue!='')){
                upperValue = parseFloat(item.upperValue);
                if(measuredValue<=upperValue){
                  item.individualJudgment =1
                }else{
                  item.individualJudgment =2
                  flag = false;
                }
              }else if((item.downValue&&item.downValue!='')&&(item.upperValue||item.upperValue!='')){
                downValue = parseFloat(item.downValue);
                if(measuredValue>=downValue){
                  item.individualJudgment =1
                }else{
                  item.individualJudgment =2
                  flag = false;
                }
              }else{
                if(measuredValue>=downValue&&measuredValue<=upperValue){
                  item.individualJudgment =1
                }else{
                  item.individualJudgment =2
                  flag = false;
                }
              }

            }
          }else{
            flag = false;
          }

        })



        this.inspectResult = flag?1:2;
        if(this.dataSource.length==0){
          this.inspectResult = 2;
        }
      },

      /**  加载时自动触发判断表格里所有单项判定是否PASS,全部PASS则判定选项变成合格,否则不合格 this.inspectResult的值控制检验结果
       * 单项判定 individualJudgment
       */
      pan_ding() {
        // let dataSource = this.dataSource;
        let pass = 0;
        for (let i = 0; i < this.dataSource.length; i++) {
          if (this.dataSource[i].individualJudgment != "1") {
            pass = 0;
            console.log("质量判定不合格");
            return (this.inspectResult = 2);
          } else {
            pass = pass + 1;
          }
        }
        if (pass > 0) {
          console.log("质量判定合格");
          this.inspectResult = 1;
        }
      },
      setdefColumns() {
        if (this.columns.length > 12) {

        }
      },
      //确定按钮
      handleSearch(selectedKeys, confirm, dataIndex) {
        confirm();
        this.searchText = selectedKeys[0];
        this.searchedColumn = dataIndex;
      },
      //取消按钮
      handleReset(clearFilters) {
        clearFilters();
        this.searchText = "";
      },
      //确定时间
      handleSearchDate(selectedKeys, confirm, dataIndex) {
        confirm();
        this.searchText = selectedKeys[0];
        this.searchedColumn = dataIndex;
        this.searchQuery();
      },
      // 清除时间
      handleResetDate(clearFilters, begin, end) {
        if (this.queryParam[begin] || this.queryParam[end]) {
          this.queryParam[begin] = "";
          this.queryParam[end] = "";
          clearFilters();
          this.searchText = "";
          this.searchQuery();
        } else {
          clearFilters();
          this.searchText = "";
        }
      },
      getKey() {
        const dataItem = [];
        setTimeout(() => {
          this.columns.forEach((item) => {
            dataItem.push({ text: item.title, value: item.dataIndex });
          });
        }, 100);
        return dataItem;
      },
      getControl(dic) {
        const dataItem = [];
        initDictOptions(dic).then((res) => {
          res.data.forEach((item) => {
            dataItem.push({ text: item.text, value: item.value });
          });
        });
        return dataItem;
      },
      initDictConfig() {
        // 用值类型的值发送请求查询数据字典里的值类型的值对应的字符串
        initDictOptions("inspect_value_type").then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, "valueType", res.data);
            console.log("检验结果的值对应的字符串", res.data);
          }
        });
        // 用检验结果的值发送请求查询数据字典里的检验结果的值对应的字符串
        initDictOptions("mes_individual_judgment").then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, "individualJudgment", res.data);
          }
          console.log("检验结果的值对应的字符串", res.data);
        });
      },

      clearList() {
        // this.dataSource = [];
        this.selectedRowKeys = [];
        this.ipagination.current = 1;
      },
      //2020/7/9
      showLinkButton(item, record) {
        let btn = new ButtonExpHandler(item.exp, record);
        return btn.show;
      },
      initButtonList() {
        getAction(`${this.url.getColumns}1f1fd813bd5446749f7f6f33bff10658`).then(
                (res) => {
                  console.log("--获取自定义按钮->>", res);
                  if (res.success) {
                    this.code = res.data.code;
                    this.initCgButtonList(res.data.cgButtonList);
                    this.initCgEnhanceJs(res.data.enhanceJs);
                  } else {
                    this.$message.warning(res.msg);
                  }
                }
        );
      },
      initCgEnhanceJs(enhanceJs) {
        //console.log("--onlineList-js增强",enhanceJs)
        if (enhanceJs) {
          let Obj = eval("(" + enhanceJs + ")");
          this.EnhanceJS = new Obj(getAction, postAction, deleteAction);
          this.cgButtonJsHandler("created");
        } else {
          this.EnhanceJS = "";
        }
      },
      initCgButtonList(btnList) {
        let linkArr = [];
        let buttonArr = [];
        if (btnList && btnList.length > 0) {
          for (let i = 0; i < btnList.length; i++) {
            let temp = btnList[i];
            if (temp.buttonStyle == "button") {
              buttonArr.push(temp);
            } else if (temp.buttonStyle == "link") {
              linkArr.push(temp);
            }
          }
        }
        this.cgButtonLinkList = [...linkArr];
        this.cgButtonList = [...buttonArr];
        console.log("链接增强", this.cgButtonLinkList);
      },
      cgButtonJsHandler(buttonCode) {
        if (this.EnhanceJS[buttonCode]) {
          this.EnhanceJS[buttonCode](this);
        }
      },
      cgButtonActionHandler(buttonCode) {
        //处理自定义button的 需要配置该button自定义sql
        if (!this.selectedRowKeys || this.selectedRowKeys.length == 0) {
          this.$message.warning("请先选中一条记录");
          return false;
        }
        if (this.selectedRowKeys.length > 1) {
          this.$message.warning("请只选中一条记录");
          return false;
        }
        let params = {
          formId: this.code,
          buttonCode: buttonCode,
          dataId: this.selectedRowKeys[0],
        };
        console.log("自定义按钮请求后台参数：", params);
        postAction(this.url.buttonAction, params).then((res) => {
          if (res.success) {
            this.loadData();
            this.$message.success("处理完成!");
          } else {
            this.$message.warning("处理失败!");
          }
        });
      },
      cgButtonLinkHandler(record, buttonCode, optType) {
        if (optType == "js") {
          if (this.EnhanceJS[buttonCode]) {
            this.EnhanceJS[buttonCode](this, record);
          }
        } else if (optType == "action") {
          let params = {
            formId: this.code,
            buttonCode: buttonCode,
            dataId: record.id,
          };
          console.log("自定义按钮link请求后台参数：", params);
          postAction(this.url.buttonAction, params).then((res) => {
            if (res.success) {
              this.loadData();
              this.$message.success("处理完成!");
            } else {
              this.$message.warning("处理失败!");
            }
          });
        }
      },
    },
  };
</script>

<style scoped>
  @import url("~@assets/less/common.less");
  .title {
    padding: 8px 12px;
    background: #fafafa;
  }
  .title:not(:first-child) {
    margin-top: 25px;
  }
</style>

